package com.baimuzhi.live.entity;

import com.baimuzhi.common.entity.BaseEntity;
import lombok.Data;
import org.springframework.stereotype.Component;

/**
 * @ClassName : Live
 * @Description :
 * @Author : 肖叶茂
 * @Date: 2023/1/18  16:35
 */


@Data
@Component
public class Live extends BaseEntity {
    //配置信息

    //直播id
    private String id;
    //直播配置服务器
    private LiveConfig liveConfig;
    //直播名称
    private String name;
    //直播秘钥
    private String pass;
    //开启的用户id
    private String userId;

    //直播推流地址
    private String rtmpUrl;


    //直播拉流地址
    private String viewRtmpUrl;


    //直播拉流地址

    private String viewFlvUrl;

    //直播拉流地址
    private String viewHlsUrl;



    //是否正在直播
    private Boolean canView;

    //返回推流地址
    public String getRtmpUrl(){
//        rtmp://localhost:1935/{appname}/{channelkey}
        return "rtmp://"+liveConfig.getUrl()+":"+liveConfig.getRtmp()+"/"+liveConfig.getId()+"/"+pass;
    }


    //返回拉流地址
    public String viewRtmp(){
//        rtmp://localhost:1935/{appname}/movie
        return "rtmp://"+liveConfig.getUrl()+":"+liveConfig.getRtmp()+"/"+liveConfig.getId()+"/"+id;
    }

    public String viewFlv(){
//      http://127.0.0.1:7001/{appname}/movie.flv
        return "http://"+liveConfig.getUrl()+":"+liveConfig.getFlv()+"/"+liveConfig.getId()+"/"+id+".flv";
    }

    public String viewHls(){
//       http://127.0.0.1:7002/{appname}/movie.m3u8
        return "http://"+liveConfig.getUrl()+":"+liveConfig.getFlv()+"/"+liveConfig.getId()+"/"+id+".m3u8";
    }


    public Live Build(){
        this.rtmpUrl = getRtmpUrl();
        this.viewRtmpUrl = viewRtmp();
        this.viewFlvUrl = viewFlv();
        this.viewHlsUrl = viewHls();
        this.canView = true;
        return this;
    }

}
